<template>
  <AuthFormCard @main="handleMain" @sub="$router.push('/manager/register')" />
</template>

<script setup lang="ts">
import AuthFormCard from '@/components/auth/AuthFormCard.vue';
import { accountLogin } from '@/api';
import { AuthUSerType } from '@/types/user';
import { useRouter } from 'vue-router';
import { setUser, getToken } from '@/utils/auth';
import { onMounted } from 'vue';

const router = useRouter();
function handleMain(params: AuthUSerType) {
  accountLogin(params).then(res => {
    if (res) {
      setUser(res);
      setTimeout(() => router.push('/manager/home'), 2000);
    }
  });
}

onMounted(() => {
  if (getToken()) {
    router.push('/manager/home');
  }
});
</script>

<style scoped></style>
